<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * 首页
 * @author chenhuan
 *
 */
class Moneymoremore extends MY_Controller {
    /*     * ************************************1:开户接口******************************************************* */

    /**
     * 注册，开户
     */
    public function registerbind() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $userObj = $this->session->userdata('zjy_user');
        $this->load->model("User_model");
        $user = $this->User_model->get_by_uid($userObj['user_id']);

        if ($user['phone_status'] != 1) {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('请先手机认证');window.location.href='/user/phone';</script>";
            return;
        } elseif ($user['real_status'] != 1) {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('请先实名认证');window.location.href='/user/realname';</script>";
            return;
        } elseif ($user['email_status'] != 1) {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('请先邮箱认证认证');window.location.href='/user/email';</script>";
            return;
        }

        $RegisterType = "2";
        $AccountType = "";
        $Mobile = $user['phone'];
        $Email = $user['email'];
        $RealName = $user['realname'];
        $IdentificationNo = $user['card_id'];

        $img_file = $user['card_pic1'];
        $imgbin = file_get_contents($img_file);
        $imgstr = bin2hex($imgbin);
        $Image1 = $imgstr;

        $img_file2 = $user['card_pic2'];
        $imgbin2 = file_get_contents($img_file2);
        $imgstr2 = bin2hex($imgbin2);
        $Image2 = $imgstr2;

        $LoanPlatformAccount = $user['username'];
        $PlatformMoneymoremore = MONEYMOREMOREPID;
        if ($this->common->getAntiState() == 0) {
            $RandomTimeStamp = "";
        } else if ($this->common->getAntiState() == 1) {
            $RandomTimeStamp = $this->common->getRandomTimeStamp();
        }
        $Remark1 = $userObj['user_id'];
        $Remark2 = "";
        $Remark3 = "";
        $ReturnURL = "http://" . $_SERVER ["HTTP_HOST"] . "/moneymoremore/registerbindreturn.html";
        $NotifyURL = "http://" . $_SERVER ["HTTP_HOST"] . "/moneymoremore/registerbindnotify.html";

        $dataStr = $RegisterType . $AccountType . $Mobile . $Email . $RealName . $IdentificationNo . $Image1 . $Image2 . $LoanPlatformAccount . $PlatformMoneymoremore . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ReturnURL . $NotifyURL;

        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA ();
        $SignInfo = $this->rsa->sign($dataStr);
        $officialAction = MONEYMOREMOREURL . "/loan/toloanregisterbind.action";
        echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
        echo '正在向第三方发送验证服务，可能需要一点时间，请稍后···';
        echo "<form id=\"formu\" name=\"formu\" action=\"" . $officialAction . "\" method=\"post\">";
        echo "<input id=\"RegisterType\" name=\"RegisterType\" value=\"" . $RegisterType . "\" type=\"hidden\" />";
        echo "<input id=\"AccountType\" name=\"AccountType\" value=\"" . $AccountType . "\" type=\"hidden\" />";
        echo "<input id=\"Mobile\" name=\"Mobile\" value=\"" . $Mobile . "\" type=\"hidden\" />";
        echo "<input id=\"Email\" name=\"Email\" value=\"" . $Email . "\" type=\"hidden\" />";
        echo "<input id=\"RealName\" name=\"RealName\" value=\"" . $RealName . "\" type=\"hidden\" />";
        echo "<input id=\"IdentificationNo\" name=\"IdentificationNo\" value=\"" . $IdentificationNo . "\" type=\"hidden\" />";
        echo "<input id=\"Image1\" name=\"Image1\" value=\"" . $Image1 . "\" type=\"hidden\" />";
        echo "<input id=\"Image2\" name=\"Image2\" value=\"" . $Image2 . "\" type=\"hidden\" />";
        echo "<input id=\"LoanPlatformAccount\" name=\"LoanPlatformAccount\" value=\"" . $LoanPlatformAccount . "\" type=\"hidden\" />";
        echo "<input id=\"PlatformMoneymoremore\" name=\"PlatformMoneymoremore\" value=\"" . $PlatformMoneymoremore . "\" type=\"hidden\" />";
        echo "<input id=\"RandomTimeStamp\" name=\"RandomTimeStamp\" value=\"" . $RandomTimeStamp . "\" type=\"hidden\" />";
        echo "<input id=\"Remark1\" name=\"Remark1\" value=\"" . $Remark1 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark2\" name=\"Remark2\" value=\"" . $Remark2 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark3\" name=\"Remark3\" value=\"" . $Remark3 . "\" type=\"hidden\" />";
        echo "<input id=\"ReturnURL\" name=\"ReturnURL\" value=\"" . $ReturnURL . "\" type=\"hidden\" />";
        echo "<input id=\"NotifyURL\" name=\"NotifyURL\" value=\"" . $NotifyURL . "\" type=\"hidden\" />";
        echo "<input id=\"SignInfo\" name=\"SignInfo\" value=\"" . $SignInfo . "\" type=\"hidden\" />";
        echo "</form>";
        echo "<script language=\"javascript\">window.onload=function(){document.formu.submit();}</script>";
    }

    /**
     * 开户返回函数
     * Enter description here ...
     */
    public function registerbindreturn() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $AccountType = $_POST["AccountType"];
        $AccountNumber = $_POST["AccountNumber"];
        $Mobile = $_POST["Mobile"];
        $Email = $_POST["Email"];
        $RealName = $_POST["RealName"];
        $IdentificationNo = $_POST["IdentificationNo"];
        $LoanPlatformAccount = $_POST["LoanPlatformAccount"];
        $MoneymoremoreId = $_POST["MoneymoremoreId"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuthFee = $_POST["AuthFee"];
        $AuthState = $_POST["AuthState"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $AccountNumber . $Mobile . $Email . $RealName . $IdentificationNo . $LoanPlatformAccount . $MoneymoremoreId . $PlatformMoneymoremore . $AuthFee . $AuthState . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        if ($ResultCode == 88) {
            $this->load->model("User_model");
            $setArr['mmm_id'] = $MoneymoremoreId;
            $this->User_model->update($setArr, array('user_id' => $Remark1));
            //self::backcharge($Remark1,EXPERIENCE_GOLD,"注册体验金");
            echo "<script>alert('SUCCESS');window.location.href='/user/center';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    /**
     * 开户返回函数
     * Enter description here ...
     */
    public function registerbindnotify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $AccountType = $_POST["AccountType"];
        $AccountNumber = $_POST["AccountNumber"];
        $Mobile = $_POST["Mobile"];
        $Email = $_POST["Email"];
        $RealName = $_POST["RealName"];
        $IdentificationNo = $_POST["IdentificationNo"];
        $LoanPlatformAccount = $_POST["LoanPlatformAccount"];
        $MoneymoremoreId = $_POST["MoneymoremoreId"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuthFee = $_POST["AuthFee"];
        $AuthState = $_POST["AuthState"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $AccountNumber . $Mobile . $Email . $RealName . $IdentificationNo . $LoanPlatformAccount . $MoneymoremoreId . $PlatformMoneymoremore . $AuthFee . $AuthState . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        if ($ResultCode == 88) {
            $this->load->model("User_model");
            $setArr['mmm_id'] = $MoneymoremoreId;
            $this->User_model->update($setArr, array('user_id' => $Remark1));
            //self::backcharge($Remark1,EXPERIENCE_GOLD,"注册体验金");
            echo "SUCCESS";
        }
    }

    /*     * ******************************************************************************************************************** */

    public function toloanrecharge($rechargeid) {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $userObj = $this->session->userdata('zjy_user');
        $this->load->model("User_model");
        $user = $this->User_model->get_by_uid($userObj['user_id']);

        $this->load->model('Accountrecharge_model', 'recharge');
        $rechargeObj = $this->recharge->get_one(array('id' => $rechargeid));

        $RechargeMoneymoremore = $user['mmm_id'];
        $PlatformMoneymoremore = MONEYMOREMOREPID;
        $OrderNo = $rechargeObj['trade_no'];
        $Amount = $rechargeObj['money'];
        $RechargeType = "";
        $FeeType = "";
        $CardNo = "";
        $common = new Common();
        if ($common->getAntiState() == 0) {
            $RandomTimeStamp = "";
        } else if ($common->getAntiState() == 1) {
            $RandomTimeStamp = $common->getRandomTimeStamp();
        }
        $Remark1 = "";
        $Remark2 = "";
        $Remark3 = "";
        $ReturnURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/rechargereturn.html";
        $NotifyURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/rechargenotify.html";

        $dataStr = $RechargeMoneymoremore . $PlatformMoneymoremore . $OrderNo . $Amount . $RechargeType . $FeeType . $CardNo . $ReturnURL . $NotifyURL;
        if ($common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $SignInfo = $rsa->sign($dataStr);

        if (!empty($CardNo)) {
            $CardNo = $rsa->encrypt($CardNo);
        }
        $officialAction = MONEYMOREMOREURL . "/loan/toloanrecharge.action";

        echo "<form id=\"formu\" name=\"formu\" action=\"" . $officialAction . "\" method=\"post\">";
        echo "<input id=\"RechargeMoneymoremore\" name=\"RechargeMoneymoremore\" value=\"" . $RechargeMoneymoremore . "\" type=\"hidden\" />";
        echo "<input id=\"PlatformMoneymoremore\" name=\"PlatformMoneymoremore\" value=\"" . $PlatformMoneymoremore . "\" type=\"hidden\" />";
        echo "<input id=\"OrderNo\" name=\"OrderNo\" value=\"" . $OrderNo . "\" type=\"hidden\" />";
        echo "<input id=\"Amount\" name=\"Amount\" value=\"" . $Amount . "\" type=\"hidden\" />";
        echo "<input id=\"RechargeType\" name=\"RechargeType\" value=\"" . $RechargeType . "\" type=\"hidden\" />";
        echo "<input id=\"FeeType\" name=\"FeeType\" value=\"" . $FeeType . "\" type=\"hidden\" />";
        echo "<input id=\"CardNo\" name=\"CardNo\" value=\"" . $CardNo . "\" type=\"hidden\" />";
        echo "<input id=\"RandomTimeStamp\" name=\"RandomTimeStamp\" value=\"" . $RandomTimeStamp . "\" type=\"hidden\" />";
        echo "<input id=\"Remark1\" name=\"Remark1\" value=\"" . $Remark1 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark2\" name=\"Remark2\" value=\"" . $Remark2 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark3\" name=\"Remark3\" value=\"" . $Remark3 . "\" type=\"hidden\" />";
        echo "<input id=\"ReturnURL\" name=\"ReturnURL\" value=\"" . $ReturnURL . "\" type=\"hidden\" />";
        echo "<input id=\"NotifyURL\" name=\"NotifyURL\" value=\"" . $NotifyURL . "\" type=\"hidden\" />";
        echo "<input id=\"SignInfo\" name=\"SignInfo\" value=\"" . $SignInfo . "\" type=\"hidden\" />";
        echo "<script language=\"javascript\">window.onload=function(){document.formu.submit();}</script>";
        echo "</form>";
    }

    /**
     * 通知地址
     */
    public function rechargereturn(){
        $this->backrechargereturn();
    }
    /**
     * 通知地址
     */
    public function backrechargereturn() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $RechargeMoneymoremore = $_POST["RechargeMoneymoremore"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $LoanNo = $_POST["LoanNo"];
        $OrderNo = $_POST["OrderNo"];
        $Amount = $_POST["Amount"];
        $RechargeType = $_POST["RechargeType"];
        $CardNoList = $_POST["CardNoList"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        if (!empty($CardNoList)) {
            $rsa = new RSA();
            $CardNoList = $rsa->decrypt($CardNoList);
            if (empty($CardNoList)) {
                $CardNoList = "";
            }
        }

        $dataStr = $RechargeMoneymoremore . $PlatformMoneymoremore . $LoanNo . $OrderNo . $Amount . $RechargeType . $CardNoList . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        if ($ResultCode == 88) {
            /* $this->load->model('Accountrecharge_model', 'recharge');
              $ret = $this->recharge->onreturn(array("trade_no"=>$OrderNo,"loanno"=>$LoanNo)); */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('充值成功');window.location.href='/account/recharge_log.html';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            $this->success("充值失败：" . $Message, "/member/charge#fragment-2");
        }
    }

    public function rechargenotify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $RechargeMoneymoremore = $_POST["RechargeMoneymoremore"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $LoanNo = $_POST["LoanNo"];
        $OrderNo = $_POST["OrderNo"];
        $Amount = $_POST["Amount"];
        $RechargeType = $_POST["RechargeType"];
        $CardNoList = $_POST["CardNoList"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        if (!empty($CardNoList)) {
            $rsa = new RSA();
            $CardNoList = $rsa->decrypt($CardNoList);
            if (empty($CardNoList)) {
                $CardNoList = "";
            }
        }

        $dataStr = $RechargeMoneymoremore . $PlatformMoneymoremore . $LoanNo . $OrderNo . $Amount . $RechargeType . $CardNoList . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        if ($ResultCode == 88) {
            $this->load->model('Accountrecharge_model', 'recharge');
            $ret = $this->recharge->onreturn(array("trade_no" => $OrderNo, "loanno" => $LoanNo));
            echo "SUCCESS";
        } else {
            echo "后台通知:" . $verifySignature;
            echo "<br>";
            echo "返回码:" . $ResultCode;
        }
    }

    public function toloanwithdraws($cashid) {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $this->load->model('Accountcash_model', 'cash');
        $cashObj = $this->cash->get_by_id($cashid);

        $userObj = $this->session->userdata('zjy_user');
        $this->load->model("User_model");
        $user = $this->User_model->get_by_uid($userObj['user_id']);

        $WithdrawMoneymoremore = $user['mmm_id'];
        $PlatformMoneymoremore = MONEYMOREMOREPID;
        $OrderNo = 'T-' . $cashObj['id'];
        $Amount = $cashObj['total'];
        $FeePercent = 0;
        $FeeMax = ''; //$cashObj['fee'];
        $CardNo = $cashObj['account'];
        $CardType = 0;
        $BankCode = $cashObj['bank'];
        $BranchBankName = $cashObj['branch'];
        $Province = $cashObj['province'];
        $City = $cashObj['city'];
        if ($this->common->getAntiState() == 0) {
            $RandomTimeStamp = "";
        } else if ($this->common->getAntiState() == 1) {
            $RandomTimeStamp = $this->common->getRandomTimeStamp();
        }
        $Remark1 = "";
        $Remark2 = "";
        $Remark3 = "";
        $ReturnURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/withdrawsreturn.html";
        $NotifyURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/withdrawsnotify.html";

        $dataStr = $WithdrawMoneymoremore . $PlatformMoneymoremore . $OrderNo . $Amount . $FeePercent . $FeeMax . $CardNo . $CardType . $BankCode . $BranchBankName . $Province . $City . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ReturnURL . $NotifyURL;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $SignInfo = $this->rsa->sign($dataStr);

        $CardNo = $this->rsa->encrypt($CardNo);

        $officialAction = MONEYMOREMOREURL . "/loan/toloanwithdraws.action";

        echo "<form id=\"formu\" name=\"formu\" action=\"" . $officialAction . "\" method=\"post\">";
        echo "<input id=\"WithdrawMoneymoremore\" name=\"WithdrawMoneymoremore\" value=\"" . $WithdrawMoneymoremore . "\" type=\"hidden\" />";
        echo "<input id=\"PlatformMoneymoremore\" name=\"PlatformMoneymoremore\" value=\"" . $PlatformMoneymoremore . "\" type=\"hidden\" />";
        echo "<input id=\"OrderNo\" name=\"OrderNo\" value=\"" . $OrderNo . "\" type=\"hidden\" />";
        echo "<input id=\"Amount\" name=\"Amount\" value=\"" . $Amount . "\" type=\"hidden\" />";
        echo "<input id=\"FeePercent\" name=\"FeePercent\" value=\"" . $FeePercent . "\" type=\"hidden\" />";
        echo "<input id=\"FeeMax\" name=\"FeeMax\" value=\"" . $FeeMax . "\" type=\"hidden\" />";
        echo "<input id=\"CardNo\" name=\"CardNo\" value=\"" . $CardNo . "\" type=\"hidden\" />";
        echo "<input id=\"CardType\" name=\"CardType\" value=\"" . $CardType . "\" type=\"hidden\" />";
        echo "<input id=\"BankCode\" name=\"BankCode\" value=\"" . $BankCode . "\" type=\"hidden\" />";
        echo "<input id=\"BranchBankName\" name=\"BranchBankName\" value=\"" . $BranchBankName . "\" type=\"hidden\" />";
        echo "<input id=\"Province\" name=\"Province\" value=\"" . $Province . "\" type=\"hidden\" />";
        echo "<input id=\"City\" name=\"City\" value=\"" . $City . "\" type=\"hidden\" />";
        echo "<input id=\"RandomTimeStamp\" name=\"RandomTimeStamp\" value=\"" . $RandomTimeStamp . "\" type=\"hidden\" />";
        echo "<input id=\"Remark1\" name=\"Remark1\" value=\"" . $Remark1 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark2\" name=\"Remark2\" value=\"" . $Remark2 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark3\" name=\"Remark3\" value=\"" . $Remark3 . "\" type=\"hidden\" />";
        echo "<input id=\"ReturnURL\" name=\"ReturnURL\" value=\"" . $ReturnURL . "\" type=\"hidden\" />";
        echo "<input id=\"NotifyURL\" name=\"NotifyURL\" value=\"" . $NotifyURL . "\" type=\"hidden\" />";
        echo "<input id=\"SignInfo\" name=\"SignInfo\" value=\"" . $SignInfo . "\" type=\"hidden\" />";
        echo "<script language=\"javascript\">window.onload=function(){document.formu.submit();}</script>";
        echo "</form>";
    }

    /*     * *****************************************5:提现************************************************************** */

    public function withdrawsreturn() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $WithdrawMoneymoremore = $_POST["WithdrawMoneymoremore"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $LoanNo = $_POST["LoanNo"];
        $OrderNo = $_POST["OrderNo"];
        $Amount = $_POST["Amount"];
        $FeeMax = $_POST["FeeMax"];
        $FeeWithdraws = $_POST["FeeWithdraws"];
        $FeePercent = $_POST["FeePercent"];
        $Fee = $_POST["Fee"];
        $FreeLimit = $_POST["FreeLimit"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $WithdrawMoneymoremore . $PlatformMoneymoremore . $LoanNo . $OrderNo . $Amount . $FeeMax . $FeeWithdraws . $FeePercent . $Fee . $FreeLimit . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $SignInfo = $this->rsa->sign($dataStr);
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        $cashid = explode("-", $OrderNo);
        $this->load->model('Accountcash_model');
        $this->load->model('Account_model');
        $cashObj = $this->Accountcash_model->get_by_id($cashid[1]);
        $user_account = $this->Account_model->get_account($cashObj['user_id']);
        if ($ResultCode == 88) {
            /* $data["fstatus"]			= 4;
              $data["review_remark"]		= "钱多多审核通过";
              $data["review_time"]		= time();
              $data["review_ip"]			= $this->input->ip_address();
              $data['mmm_loanno']			= $LoanNo;
              $ret = $this->Accountcash_model->update($cashid[1], $data);
              $log = array(
              'user_id' => $cashObj['user_id'],
              'ftype' => RECHARGE_SUCCESS,//提现审核通过
              'total' => $user_account['total']-$cashObj['total'],
              'money' => $cashObj['total'],
              'use_money' => $user_account['use_money'],
              'no_use_money' => $user_account['no_use_money']-$cashObj['total'],
              'collection' => $user_account['collection'],
              'to_user' => 1,
              'remark' => '提现审核通过',
              'add_time' => time(),
              'addip' => $this->input->ip_address(),
              );
              $ret = $this->Account_model->addlog($log);
              if ($ret){
              //提醒设置
              $this->load->model('Message_model');
              $msg = array(
              'sent_user' => '1',
              'receive_user' => $log['user_id'],
              'name' => '提现审核通过',
              'fstatus' => '0',
              'message_type' => 'system',
              'sented' => '0',
              'deltype' => '0',
              'content' => '您于 '.date('Y-m-d H:i:s').' 提现：'.$cashObj['total'].'元审核通过，到账：'.$cashObj['credited'].'元，手续费：'.$cashObj['fee'].'元。',
              'add_time' => time(),
              'addip' => $this->input->ip_address()
              );
              $this->Message_model->send($msg);
              } */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('提现成功');window.location.href='/account/cashed.html';</script>";
        } elseif ($ResultCode == 89) {
            /* $data["fstatus"]			= 1;
              $data["verify_userid"]      = 1;
              $data["verify_remark"]		= "钱多多审核通过";
              $data["verify_time"]		= time();
              $data["verify_ip"]			= $this->input->ip_address();
              $ret = $this->Accountcash_model->update($OrderNo, $data); */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('提现成功');window.location.href='/account/cashed.html';</script>";
        } elseif ($ResultCode == 90) {
            /* $data["fstatus"]			= 1;
              $data["verify_userid"]      = 1;
              $data["verify_remark"]		= "钱多多审核通过";
              $data["verify_time"]		= time();
              $data["verify_ip"]			= $this->input->ip_address();
              $ret = $this->Accountcash_model->update($OrderNo, $data); */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('提现成功');window.location.href='/account/cashed.html';</script>";
        } else {
            /* $log = array(
              'user_id' => $cashObj['user_id'],
              'ftype' => RECHARGE_FALSE,//提现失败
              'money' => $cashObj['total'],
              'total' => $user_account['total'],
              'use_money' => $user_account['use_money']+$cashObj['total'],
              'no_use_money' => $user_account['no_use_money']-$cashObj['total'],
              'collection' => $user_account['collection'],
              'to_user' => 1,
              'remark' => '提现审核未通过',
              'add_time' => time(),
              'addip' => $this->input->ip_address(),
              );
              $ret = $this->Account_model->addlog($log);

              $data["fstatus"]			= 2;
              $data["verify_userid"]      = 1;
              $data["verify_remark"]		= "钱多多审核不通过";
              $data["verify_time"]		= time();
              $data["verify_ip"]			= $this->input->ip_address();
              $ret = $this->Accountcash_model->update($OrderNo, $data); */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    /*     * *****************************************5:提现************************************************************** */

    public function withdrawsnotify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $WithdrawMoneymoremore = $_POST["WithdrawMoneymoremore"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $LoanNo = $_POST["LoanNo"];
        $OrderNo = $_POST["OrderNo"];
        $Amount = $_POST["Amount"];
        $FeeMax = $_POST["FeeMax"];
        $FeeWithdraws = $_POST["FeeWithdraws"];
        $FeePercent = $_POST["FeePercent"];
        $Fee = $_POST["Fee"];
        $FreeLimit = $_POST["FreeLimit"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $WithdrawMoneymoremore . $PlatformMoneymoremore . $LoanNo . $OrderNo . $Amount . $FeeMax . $FeeWithdraws . $FeePercent . $Fee . $FreeLimit . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $SignInfo = $this->rsa->sign($dataStr);
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        $cashid = explode("-", $OrderNo);
        $this->load->model('Accountcash_model');
        $this->load->model('Account_model');
        $cashObj = $this->Accountcash_model->get_by_id($cashid[1]);
        $user_account = $this->Account_model->get_account($cashObj['user_id']);
        if ($ResultCode == 88) {
            $log = array(
                'user_id' => $cashObj['user_id'],
                'ftype' => RECHARGE_SUCCESS, //提现审核通过
                'total' => $user_account['total'] - $cashObj['total'],
                'money' => $cashObj['total'],
                'use_money' => $user_account['use_money'],
                'no_use_money' => $user_account['no_use_money'] - $cashObj['total'],
                'collection' => $user_account['collection'],
                'to_user' => 1,
                'remark' => '提现审核通过',
                'add_time' => time(),
                'addip' => $this->input->ip_address(),
            );
            $ret = $this->Account_model->addlog($log);
            if ($ret) {
                //提醒设置
                $this->load->model('Message_model');
                $msg = array(
                    'sent_user' => '1',
                    'receive_user' => $log['user_id'],
                    'name' => '提现审核通过',
                    'fstatus' => '0',
                    'message_type' => 'system',
                    'sented' => '0',
                    'deltype' => '0',
                    'content' => '您于 ' . date('Y-m-d H:i:s') . ' 提现：' . $cashObj['total'] . '元审核通过，到账：' . $cashObj['credited'] . '元，手续费：' . $cashObj['fee'] . '元。',
                    'add_time' => time(),
                    'addip' => $this->input->ip_address()
                );
                $this->Message_model->send($msg);
            }
            $data["fstatus"] = 4;
            $data["verify_userid"] = 1;
            $data["verify_remark"] = "体现审核通过";
            $data["verify_time"] = time();
            $data["mmm_loanno"] = $LoanNo;
            $data["verify_ip"] = $this->input->ip_address();
            $ret = $this->Accountcash_model->update($cashid[1], $data);
            echo "SUCCESS";
        } elseif ($ResultCode == 89) {
            $data["fstatus"] = 1;
            $data["verify_userid"] = 1;
            $data["verify_remark"] = "钱多多审核通过";
            $data["verify_time"] = time();
            $data["mmm_loanno"] = $LoanNo;
            $data["verify_ip"] = $this->input->ip_address();
            $ret = $this->Accountcash_model->update($cashid[1], $data);
            echo "SUCCESS";
        } elseif ($ResultCode == 90) {
            $data["fstatus"] = 1;
            $data["verify_userid"] = 1;
            $data["verify_remark"] = "钱多多审核通过";
            $data["verify_time"] = time();
            $data["mmm_loanno"] = $LoanNo;
            $data["verify_ip"] = $this->input->ip_address();
            $ret = $this->Accountcash_model->update($cashid[1], $data);
            echo "SUCCESS";
        } else {
            $log = array(
                'user_id' => $cashObj['user_id'],
                'ftype' => RECHARGE_FALSE, //提现失败
                'money' => $cashObj['total'],
                'total' => $user_account['total'],
                'use_money' => $user_account['use_money'] + $cashObj['total'],
                'no_use_money' => $user_account['no_use_money'] - $cashObj['total'],
                'collection' => $user_account['collection'],
                'to_user' => 1,
                'remark' => '提现审核未通过',
                'add_time' => time(),
                'addip' => $this->input->ip_address(),
            );
            $ret = $this->Account_model->addlog($log);

            $data["fstatus"] = 2;
            $data["verify_userid"] = 1;
            $data["verify_remark"] = "钱多多审核不通过";
            $data["verify_time"] = time();
            $data["verify_ip"] = $this->input->ip_address();
            $ret = $this->Accountcash_model->update($cashid[1], $data);
        }
    }

    /*     * ***********************************7:授权接口******************************************* */

    /**
     * 授权
     * Enter description here ...
     * @param unknown_type $action
     */
    public function shouquan($action = 1) {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $userObj = $this->session->userdata('zjy_user');
        $this->load->model("User_model");
        $user = $this->User_model->get_by_uid($userObj['user_id']);

        $MoneymoremoreId = $user['mmm_id'];
        $PlatformMoneymoremore = MONEYMOREMOREPID;
        $AuthorizeTypeOpen = $action;
        $AuthorizeTypeClose = "";
        if ($this->common->getAntiState() == 0) {
            $RandomTimeStamp = "";
        } else if ($this->common->getAntiState() == 1) {
            $RandomTimeStamp = $this->common->getRandomTimeStamp();
        }
        $Remark1 = $user['user_id'];
        $Remark2 = "";
        $Remark3 = "";
        $ReturnURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/authorizereturn_sq.html";
        $NotifyURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/authorizenotify_sq.html";

        $dataStr = $MoneymoremoreId . $PlatformMoneymoremore . $AuthorizeTypeOpen . $AuthorizeTypeClose . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ReturnURL . $NotifyURL;
        $SignInfo = $this->rsa->sign($dataStr);

        $officialAction = MONEYMOREMOREURL . "/loan/toloanauthorize.action";

        echo "<form id=\"formu\" name=\"formu\" action=\"" . $officialAction . "\" method=\"post\">";
        echo "<input id=\"MoneymoremoreId\" name=\"MoneymoremoreId\" value=\"" . $MoneymoremoreId . "\" type=\"hidden\" />";
        echo "<input id=\"PlatformMoneymoremore\" name=\"PlatformMoneymoremore\" value=\"" . $PlatformMoneymoremore . "\" type=\"hidden\" />";
        echo "<input id=\"AuthorizeTypeOpen\" name=\"AuthorizeTypeOpen\" value=\"" . $AuthorizeTypeOpen . "\" type=\"hidden\" />";
        echo "<input id=\"AuthorizeTypeClose\" name=\"AuthorizeTypeClose\" value=\"" . $AuthorizeTypeClose . "\" type=\"hidden\" />";
        echo "<input id=\"RandomTimeStamp\" name=\"RandomTimeStamp\" value=\"" . $RandomTimeStamp . "\" type=\"hidden\" />";
        echo "<input id=\"Remark1\" name=\"Remark1\" value=\"" . $Remark1 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark2\" name=\"Remark2\" value=\"" . $Remark2 . "\" type=\"hidden\" />";
        echo "<input id=\"Remark3\" name=\"Remark3\" value=\"" . $Remark3 . "\" type=\"hidden\" />";
        echo "<input id=\"ReturnURL\" name=\"ReturnURL\" value=\"" . $ReturnURL . "\" type=\"hidden\" />";
        echo "<input id=\"NotifyURL\" name=\"NotifyURL\" value=\"" . $NotifyURL . "\" type=\"hidden\" />";
        echo "<input id=\"SignInfo\" name=\"SignInfo\" value=\"" . $SignInfo . "\" type=\"hidden\" />";
        echo "<script language=\"javascript\">window.onload=function(){document.formu.submit();}</script>";
        echo "</form>";
    }

    public function authorizereturn_sq() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $MoneymoremoreId = $_POST["MoneymoremoreId"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuthorizeTypeOpen = $_POST["AuthorizeTypeOpen"];
        $AuthorizeTypeClose = $_POST["AuthorizeTypeClose"];
        $AuthorizeType = $_POST["AuthorizeType"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $MoneymoremoreId . $PlatformMoneymoremore . $AuthorizeTypeOpen . $AuthorizeTypeClose . $AuthorizeType . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            $this->load->model("User_model");
            $setArr = array();
            if ($AuthorizeTypeOpen == "1") {
                $setArr['mmm_sq_tb'] = 1;
            } elseif ($AuthorizeTypeOpen == "2") {
                $setArr['mmm_sq_hk'] = 1;
            } elseif ($AuthorizeTypeOpen == "3") {
                $setArr['mmm_sq_ecfp'] = 1;
            }
            $this->User_model->update($setArr, array('user_id' => $Remark1));
            echo "<script>alert('SUCCESS');window.location.href='/user/center';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('授权失败" . $Message . "');window.location.href='/user/center';</script>";
        }
    }

    public function transferauditreturn_verify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $fp = fopen("d:/ch/1touzi3.txt", "w"); //文件被清空后再写入
        $flag = fwrite($fp, serialize($_REQUEST));
        fclose($fp);

        $LoanNoList = $_POST["LoanNoList"];
        $LoanNoListFail = $_POST["LoanNoListFail"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuditType = $_POST["AuditType"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];
        //print_r($_POST);exit;
        $dataStr = $LoanNoList . $LoanNoListFail . $PlatformMoneymoremore . $AuditType . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            /* $ind = explode('=',$Remark1);
              $data['id'] 				= $ind[0];
              $data['ip'] 				= $ind[1];
              $data['fstatus'] 			= $ind[2];
              $data['repayment_remark'] 	= $ind[3];
              $data['repayment_user'] 	= $ind[4];
              $this->load->model("Borrow_model");
              if($data['fstatus'] == 3){
              $flag = $this->Borrow_model->borrow_review_true($data);
              }else{
              $flag = $this->Borrow_model->borrow_review_false($data);
              }
              $borrow = $this->Borrow_model->get_borrow_obj($data['id']);
              $this->Notice(10, $borrow['user_id']); */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('操作成功');window.location.href='/ychadmin/borrow/borrowlist/?fstatus=-2';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    public function transferauditnotify_verify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $LoanNoList = $_POST["LoanNoList"];
        $LoanNoListFail = $_POST["LoanNoListFail"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuditType = $_POST["AuditType"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];
        //print_r($_POST);exit;
        $dataStr = $LoanNoList . $LoanNoListFail . $PlatformMoneymoremore . $AuditType . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            $ind = explode('=', $Remark1);
            $data['id'] = $ind[0];
            $data['ip'] = $ind[1];
            $data['fstatus'] = $ind[2];
            $data['repayment_remark'] = $ind[3];
            $data['repayment_user'] = $ind[4];
            $this->load->model("Borrow_model");
            if ($data['fstatus'] == 3) {
                $flag = $this->Borrow_model->borrow_review_true($data);
            } else {
                $flag = $this->Borrow_model->borrow_review_false($data);
            }
            $borrow = $this->Borrow_model->get_borrow_obj($data['id']);
            $this->Notice(10, $borrow['user_id']);
            echo "<script>alert('SUCCESS');window.location.href='/ychadmin/borrow/borrowlist/?fstatus=-2';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    public function transferauditreturn_creditor() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $LoanNoList = $_POST["LoanNoList"];
        $LoanNoListFail = $_POST["LoanNoListFail"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuditType = $_POST["AuditType"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];
        $dataStr = $LoanNoList . $LoanNoListFail . $PlatformMoneymoremore . $AuditType . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            /* $ind = $Remark1;
              $this->load->model("Creditor_model");
              if($Remark2 == "3"){
              $flag = $this->Creditor_model->reverify_true($ind);
              }else{
              $flag = $this->Creditor_model->reverify_false($ind);
              } */
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('操作成功');window.location.href='/ychadmin/creditor/reverify_list/?fstatus=-2';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    public function transferauditnotify_creditor() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');

        $LoanNoList = $_POST["LoanNoList"];
        $LoanNoListFail = $_POST["LoanNoListFail"];
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $AuditType = $_POST["AuditType"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];
        $dataStr = $LoanNoList . $LoanNoListFail . $PlatformMoneymoremore . $AuditType . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            $ind = $Remark1;
            $this->load->model("Creditor_model");
            if ($Remark2 == "3") {
                $flag = $this->Creditor_model->reverify_true($ind);
            } else {
                $flag = $this->Creditor_model->reverify_false($ind);
            }
            echo "SUCCESS";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    public function transferreturn_repayment() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $LoanJsonList = $_POST["LoanJsonList"];
        $LoanJsonList = utf8_decode($LoanJsonList);
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];
        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            /* $ind = explode('=',$Remark1);
              $data['repayment_id'] 	= $ind[0];
              $data['user_id'] 		= $ind[1];
              $data['ip'] 			= $ind[2];
              $this->load->model("Borrow_model");
              $flag = $this->Borrow_model->repay($data); */

            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo "<script>alert('操作成功');window.location.href='/userborrow/over/index.html';</script>";
        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    public function transfernotify_repayment() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $LoanJsonList = $_POST["LoanJsonList"];
        $LoanJsonList = utf8_decode($LoanJsonList);
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);
        if ($ResultCode == 88) {
            $ind = explode('=', $Remark1);
            $data['repayment_id'] = $ind[0];
            $data['user_id'] = $ind[1];
            $data['ip'] = $ind[2];
            $this->load->model("Borrow_model");
            $flag = $this->Borrow_model->repay($data);
            if ($flag == 1){
                echo "SUCCESS";
            } else {
                echo $flag;
            }

        } else {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
        }
    }

    function test() {
        self::backcharge(326, 10.00, "测试充值");
    }

    public function backcharge($uid, $money, $info) {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $this->load->model("User_model");
        $user = $this->User_model->get_by_uid($uid);

        $PlatformMoneymoremore = MONEYMOREMOREPID;

        $ExchangeBatchNo = "";
        $AdvanceBatchNo = "";
        $loaninfo1 = new LoanInfoBean($PlatformMoneymoremore, $user['mmm_id'], date("YmdHis"), date("YmdHis"), $ExchangeBatchNo, $AdvanceBatchNo, $money, $money, "平台充值", $info, "");
        $arrloaninfo = array('0' => array("LoanOutMoneymoremore" => $loaninfo1->LoanOutMoneymoremore,
                "LoanInMoneymoremore" => $loaninfo1->LoanInMoneymoremore,
                "OrderNo" => $loaninfo1->OrderNo,
                "BatchNo" => $loaninfo1->BatchNo,
                "ExchangeBatchNo" => $loaninfo1->ExchangeBatchNo,
                "AdvanceBatchNo" => $loaninfo1->AdvanceBatchNo,
                "Amount" => $loaninfo1->Amount,
                "FullAmount" => $loaninfo1->FullAmount,
                "TransferName" => $loaninfo1->TransferName,
                "Remark" => $loaninfo1->Remark,
                "SecondaryJsonList" => $loaninfo1->SecondaryJsonList));
        $LoanJsonList = json_encode($arrloaninfo);

        $TransferAction = "3";
        $Action = "2";
        $TransferType = "2";
        $NeedAudit = "1";
        $common = new Common();
        if ($common->getAntiState() == 0) {
            $RandomTimeStamp = "";
        } else if ($common->getAntiState() == 1) {
            $RandomTimeStamp = $common->getRandomTimeStamp();
        }
        $Remark1 = $uid;
        $Remark2 = $info;
        $Remark3 = "";
        $ReturnURL = "";
        $NotifyURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/transfernotify.html";

        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $TransferAction . $Action . $TransferType . $NeedAudit . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ReturnURL . $NotifyURL;
        if ($common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $SignInfo = $rsa->sign($dataStr);

        $LoanJsonList = urlencode($LoanJsonList);

        $post_data = array();
        $post_data['LoanJsonList'] = $LoanJsonList;
        $post_data['PlatformMoneymoremore'] = $PlatformMoneymoremore;
        $post_data['TransferAction'] = $TransferAction;
        $post_data['Action'] = $Action;
        $post_data['TransferType'] = $TransferType;
        $post_data['NeedAudit'] = $NeedAudit;
        $post_data['RandomTimeStamp'] = $RandomTimeStamp;
        $post_data['Remark1'] = $Remark1;
        $post_data['Remark2'] = $Remark2;
        $post_data['Remark3'] = $Remark3;
        $post_data['ReturnURL'] = $ReturnURL;
        $post_data['NotifyURL'] = $NotifyURL;
        $post_data['SignInfo'] = $SignInfo;

        $moreMorePlat = MONEYMOREMOREPID;
        $urlMoneymoremore = MONEYMOREMOREURL;
        $url = $urlMoneymoremore . '/loan.action';
        $o = "";
        foreach ($post_data as $k => $v) {
            $o.= "$k=" . urlencode($v) . "&";
        }
        $post_data = substr($o, 0, -1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //为了支持cookie
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $result = curl_exec($ch);
        $fp = fopen("d:/ch/bangka.txt", "a"); //文件被清空后再写入
        $flag = fwrite($fp, $result);
        fclose($fp);
        $jdate = substr($result, 1, strlen($result) - 2);
        $jdataarray = explode('},{', $jdate);
        $index = 0;
        $account_list = array();
        foreach ($jdataarray as $ja) {
            if ($index == 0) {
                $account_list[] = json_decode($ja . "}", true);
            } else {
                $account_list[] = json_decode("{" . $ja, true);
            }
            $index++;
        }
        $done = false;

        if ($account_list[1]['ResultCode'] == 88) {
            $this->load->model("Account_model");
            $account_obj = $this->Account_model->get_account($uid);
            $log = array(
                'user_id' => $uid,
                'ftype' => EXP_MONEY, //提现失败
                'money' => $money,
                'total' => $account_obj['total'] + $money,
                'use_money' => $account_obj['use_money'] + $money,
                'no_use_money' => $account_obj['no_use_money'],
                'collection' => $account_obj['collection'],
                'to_user' => 1,
                'remark' => $info,
                'add_time' => time(),
                'addip' => "127.0.0.1",
            );
            $this->Account_model->accountlog($log);
        }
        return $done;
    }

    public function transfernotify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $LoanJsonList = $_POST["LoanJsonList"];
        $LoanJsonList = utf8_decode($LoanJsonList);
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        $common = new Common();
        if ($common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $verifySignature = $rsa->verify($dataStr, $SignInfo);

        if ($ResultCode == 88) {
            echo "SUCCESS";
        } else {
            echo $Message;
        }
    }

    /**
     * 页面返回回调
     */
    public function mmmReturn() {
        //操作失败
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        if ($ResultCode != 88) {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
            echo $Message;
            return;
        }

        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $LoanJsonList = $_POST["LoanJsonList"];
        $LoanJsonList = urldecode($LoanJsonList);
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
        echo "<script>alert('操作成功');</script>";
        switch ($Remark1) {
            case 'REVIP':
                echo "<script>window.location.href='/user/vip.html';</script>";
                break;
        }
    }

    /**
     * 页面通知回调
     */
    public function mmmNotify() {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $LoanJsonList = $_POST["LoanJsonList"];
        $LoanJsonList = utf8_decode($LoanJsonList);
        $PlatformMoneymoremore = $_POST["PlatformMoneymoremore"];
        $RandomTimeStamp = $_POST["RandomTimeStamp"];
        $Remark1 = $_POST["Remark1"];
        $Remark2 = $_POST["Remark2"];
        $Remark3 = $_POST["Remark3"];
        $ResultCode = $_POST["ResultCode"];
        $Message = $_POST["Message"];
        $SignInfo = $_POST["SignInfo"];

        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ResultCode;
        if ($this->common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $verifySignature = $this->rsa->verify($dataStr, $SignInfo);

        if ($ResultCode != 88) {
            echo "后台通知:" . $verifySignature;
            echo "<br>";
            echo "返回码:" . $ResultCode;
            return;
        }

        $returnJson = json_decode(urldecode($LoanJsonList), true);
        $LoanNo = "";
        foreach ($returnJson as $jobj) {
            $LoanNo[] = $jobj['LoanNo'];
        }
        $loanstr = implode(",", $LoanNo);

        $paranmstr = explode("=", $Remark2);
        $data['id'] = $paranmstr[0];
        $data['money'] = $paranmstr[1];
        $data['ip'] = $paranmstr[2];
        $data['user_id'] = $paranmstr[3];
        $data['borrow_user_id'] = $paranmstr[4];
        $data['borrow_id'] = $paranmstr[5];
        $data['account'] = $paranmstr[6];
        $data['mmmloanno'] = $loanstr;

        switch ($Remark1) {
            case 'REVIP':
                $this->vipNotify($Remark2);
                break;
        }
        echo "SUCCESS";
    }

    /**
     * 申请VIP扣费回调
     * @param int $userId
     */
    public function vipNotify($flagStr) {
        $arr = explode('-', $flagStr);
        $userId = $arr[0];
        $setArr = array(
            'user_id' => $userId,
            'kefu_userid' => $arr[1],
            'kefu_addtime' => time(),
            'vip_status' => 1,
            'vip_remark' => '',
            'vip_money' => VIP_MONEY,
            'vip_verify_remark' => 'VIP审核通过',
            'vip_verify_time' => time(),
        );
        //加载model
        $this->load->model('User_vip_model', 'vip');
        $this->load->model('Account_model');

        $row = $this->vip->get_by_uid($userId);
        if ($row && $row['vip_status'] == 1){
            return '';
        }
        $user_account = $this->Account_model->get_account($userId);
        //事务开始
        $this->db->trans_begin();
        //扣除会员费188  VIP
        $log = array();
        $log['user_id'] = $userId;
        $log['ftype'] = VIP;
        $log['money'] = VIP_MONEY;
        $log['total'] = $user_account['total'] - $log['money'];
        $log['use_money'] = $user_account['use_money'] - $log['money'];
        $log['no_use_money'] = $user_account['no_use_money'];
        $log['collection'] = $user_account['collection'];
        $log['to_user'] = 1;
        $log['remark'] = "VIP费用扣除";
        $log['add_time'] = time();
        $log['addip'] = $arr[3];
        $log['op'] = 1;
        $mode = $userId % 100;
        $res = $this->db->insert('zjy_account_log_' . $mode, $log);
        if ($res) {
            //更新用户资金表
            $res = $this->db->query("update zjy_account set total=total-{$log['money']},use_money=use_money-{$log['money']} where user_id={$userId}");
        }
        if ($res) {
            if ($row) {
                //修改
                $res = $this->vip->update($setArr, array('user_id' => $userId));
            } else {
                //添加
                $res = $this->vip->apply($setArr);
            }
        }


        //提交事务
        if ($res) {
            $co = '用户 ' . $arr[2] . ' 申请vip';
            $this->letterStation($arr[1], 'VIP申请', $co);
            $this->letterStation($userId, 'VIP审核通过', '您的vip申请已审核通过，祝你投资愉快！');
            $this->Notice(8, $userId);
            $this->Credit($userId, 'vip');
            $this->db->trans_commit();
        } else {
            $this->db->trans_rollback();
        }

        $ret['msg'] = $this->db->trans_status() ? 'VIP审核通过！' : '操作失败，请联系客服';
        //echo json_encode($ret);
        echo "SUCCESS";
    }

}
